import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

// 自定义指令
/* Vue.directive('imgerror',{
  inserted(el,binding){
    // el 是指令所在的DOM节点信息，binding是指令所包含的信息、
    // 图片音频视频都有一个原生时间onerror,加载出错的时候触发
    // console.log(el,binding); // binding.value能拿到指令绑定的数据值
    el.onerror=()=>{
      //图片加载不出来重新给图片的src赋个地址
      //el.src="https://www/itheima.com/images/logo.png"
      el.src = binding.value
    }
  }
}) */
// 自定义指令直接换成导入自定义指令的模块，批量注册指令
import * as all from "@/directive"
Object.keys(all).forEach(val=>{
  // val是属性名，all[val]是属性值
  // 批量注册指令Vue.directive(指令名,指令配置对象)
  Vue.directive(val,all[val])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
